#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 2;
bool tab[MAX][MAX];
bool l[MAX][MAX];
bool r[MAX][MAX];
bool u[MAX][MAX];
bool d[MAX][MAX];
using ll = long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> tab[i][j];
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
l[i][j] = l[i][j-1] || tab[i][j];
u[i][j] = u[i-1][j] || tab[i][j];
}
}
for(int i = n; i > 0; i--)
{
for(int j = m; j > 0; j--)
{
r[i][j] = r[i][j+1] || tab[i][j];
d[i][j] = d[i+1][j] || tab[i][j];
}
}
ll ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(!tab[i][j])
{
ans += l[i][j-1];
ans += r[i][j+1];
ans += u[i-1][j];
ans += d[i+1][j];
}
}
}
cout << ans << endl;
return 0;
}
740A - Alyona and copybooks | 1491A - K-th Largest Value |
922B - Magic Forest | 922D - Robot Vacuum Cleaner |
408B - Garland | 1391A - Suborrays |
1700C - Helping the Nature | 982A - Row |
877A - Alex and broken contest | 919D - Substring |
362B - Petya and Staircases | 1535C - Unstable String |
1738F - Connectivity Addicts | 1342B - Binary Period |
1551C - Interesting Story | 794B - Cutting Carrot |
534B - Covered Path | 1278C - Berry Jam |
1203A - Circle of Students | 1740B - Jumbo Extra Cheese 2 |
1740A - Factorise N+M | 49B - Sum |
23A - You're Given a String | 1105C - Ayoub and Lost Array |
1624E - Masha-forgetful | 998B - Cutting |
250A - Paper Work | 1740C - Bricks and Bags |
1130A - Be Positive | 465A - inc ARG |